package UDP;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.SocketException;

public class Server {
    public static void main(String[] args) throws IOException {
        DatagramSocket socket = new DatagramSocket(9090);

        byte[] bytes = new byte[1024*64];
        DatagramPacket packet = new DatagramPacket(bytes, bytes.length);
        while (true) {
            socket.receive(packet);
            System.out.println(new String(packet.getData(),0, packet.getLength()));
            System.out.println("来自IP号为:" + packet.getAddress().getHostAddress() + " , 来自端口号为:" + packet.getPort());

            byte[] bytes1 = "响应成功!!!".getBytes();
            DatagramPacket packet1 = new DatagramPacket(bytes1,bytes1.length,packet.getAddress(),packet.getPort());
            socket.send(packet1);
            System.out.println("==================");
        }
    }
}
